package org.white.word2pdf.service.impl;

import com.aspose.words.Document;
import com.aspose.words.SaveFormat;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.commons.io.IOUtils;
import org.springframework.stereotype.Service;
import org.white.word2pdf.ErrorException;
import org.white.word2pdf.enums.ComponentType;
import org.white.word2pdf.service.Word2PdfStrategyInterface;

@Service
public class AsposeWord2PdfServiceImpl implements Word2PdfStrategyInterface {

    @Override
    public ComponentType getType() {
        return ComponentType.ASPOSE;
    }

    @Override
    public void convertToPdf(InputStream is, OutputStream os) {
        Document doc = null;
        try {
            doc = new Document(is);
            doc.save(os, SaveFormat.PDF);
        } catch (Exception e) {
            e.printStackTrace();
            throw new ErrorException("Aspose转换失败，您可以使用您的word在github提交issue");
        }
    }
}
